package com.qezhhnjy.demo.async.simple;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

/**
 * @author zhaoyangfu - 2021/1/4 13:18
 * 最简易的异步任务不需要任何配置，只需要@EnableAsync并且在方法上加上@Async即可
 * 会调用spring.task.execution配置的线程池，默认为8个线程，可进行修改配置
 */
@EnableAsync
@Slf4j
@Component
public class SimpleAsync {

    @Async
    public void first() {
        log.info("simple async first");
        ThreadUtil.sleep(55000);
        throw new RuntimeException("first");
    }
}
